package com.blueberry.codegen;


import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

public class CodeGen {

    private static final String url = "jdbc:mysql://localhost:3306/blueberry?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai";

    private static final String user = "root";

    private static final String password = "apb7@ZvT";


    private static final String[] tables = new String[]{"sys_dept"};


    public static void main(String[] args) {
        final String projectPath = System.getProperty("user.dir");
        FastAutoGenerator.create(url, user, password)
                .globalConfig(builder -> {
                    builder.author("yuqian") // 开启 swagger 模式
                            .outputDir(projectPath + "\\blueberry-modules\\blueberry-system" + "\\src\\main\\java")
                            .commentDate("yyyy-MM-dd"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.blueberry.system")
                            .entity("entity")
                            .mapper("mapper")
                            .service("service")
                            .serviceImpl("service.impl")
                            .xml("mapper.xml");
                })
                .strategyConfig(builder -> builder
                        .addInclude(tables)
                        .entityBuilder()
                        .enableLombok()
                        .enableFileOverride()
                        .addTableFills(
                                new Column("create_by", FieldFill.INSERT),
                                new Column("create_at", FieldFill.INSERT),
                                new Column("update_by", FieldFill.UPDATE),
                                new Column("update_at", FieldFill.UPDATE))
                        .logicDeleteColumnName("del_flag")
                        .controllerBuilder().disable()
                ).templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }

}
